/**
 * Created by Administrator on 2016/8/4.
 */

var topic_name, topic_type, department_id, currentID, flag = true;
function Personload() {
    $('#table').bootstrapTable({
        method: "get",
        striped: true,
        singleSelect: false,
        url:"question.json",
        dataType: "json",
        pagination: true, //分页
        pageSize: 10,
        pageNumber: 1,
        search: false, //显示搜索框
        contentType: "application/x-www-form-urlencoded",
        queryParams: null,
        columns: [
        	/*{
                checkbox:"true",
                field: '',
                align: 'center',
                valign: 'middle'
            },*/
            /*{
            	visible:false,//隐藏列
                field: 'id',
                align: 'center',
                valign: 'middle'
            },*/
            {
                title: "试题标题",
                field: 'topic_name',
                align: 'center',
                valign: 'middle'
            },
            {
                title: '试题类型',
                field: 'type',
                align: 'center',
                valign: 'middle'
            },
            {
                title: '试题级别',
                field: 'rank',
                align: 'center'
            },
            {
                title: '所属部门',
                field: 'department',
                align: 'center'
            },
                     
            {
                title: '操作',
                field: '',
                align: 'center',
                formatter: function (value, row) {
                	var e = '<a href="#" onclick="del(\'' + row.id + '\')">删除</a> '
                    var d = '<a href="updQuestion.html/' + row.id + '">编辑</a> ';
                    var g = '<a href="showQuestion.html/' + row.id + '">明细</a> '
                    return e + d + g;
                }
            }
        ]
    });
    getData();
}
function getData() {
    
	topic_name = $("#topic_name").val();
    topic_type = $("#topic_type").val();
    department_id = $("#department_id").val();
    
    $.ajax({
        type: "GET",
        url: "select_question.json",
        data:{
        	"topic_name":topic_name,
        	"topic_type":topic_type,
        	"department_id":department_id
        },
        dataType: "json",
        success: function (result) {
            if (result.data) {
                var TableData = result.data;
                $('#table').bootstrapTable("load", TableData);
            }
        }
    })
}
function add() {
    openlayer()
    currentID = "";
}
function edit(id) {
    openlayer()
    currentID = id;
}
function del(id) {
    var flag = confirm("确定删除这条数据（包含附件）吗？");
    if(flag){
    	$.ajax({
            url: "delQuestion.json",
            data: {"id":id},
            type: 'GET',
            dataType: 'json',
            success: function (data) {
                if (data.data) {
                    alert("删除成功！")
                    getData();
                } else {
                    alert("删除失败")
                }
            },
            error: function (err) {
            }
        });
    }
}
function getCurrentID() {
    return currentID;
}
function openlayer(id){
    layer.open({
        type: 2,
        title: '添加信息',
        shadeClose: true,
        shade: 0.5,
        skin: 'layui-layer-rim',
//            maxmin: true,
        closeBtn:2,
        area: ['80%', '90%'],
        shadeClose: true,
        closeBtn: 2,
        content: 'person_tail.html'
        //iframe的url
    });
}







